<?php

namespace App\Admin\Controllers;

use App\Models\Filter;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class FilterController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '表单';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Filter());
        
        $grid->column('filter_time', '统计日期');
	    //$grid->model()->orderByDesc('created_at');
        $grid->column('record_recharge', __('Record recharge'));
        $grid->column('record_send', __('Record send'));
        $grid->column('record_balance', __('Record balance'));
        $grid->column('record_order', __('Record order'));
        $grid->column('record_goods', __('Record goods'));
        $grid->column('record_storage', __('Record storage'));
        $grid->column('record_take_away', __('Record take away'));
        $grid->column('record_storage_man', __('Record storage man'));
        $grid->column('record_take_away_man', __('Record take away man'));
        $grid->column('record_pay', __('Record pay'));
        $grid->column('purchase_to_material', __('Purchase to material'));
        $grid->column('goods_sell', __('Goods sell'));
        $grid->column('record_room', __('Record room'));
        $grid->column('staff_practice', '员工培训费用');
        //$grid->column('created_at', __('Created at'));
        
        $grid->disableActions();
        $grid->filter(function (Grid\Filter $filter) {
        	$filter->disableIdFilter();
        	$filter->between('created_at', '统计时间')->datetime();
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Filter::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('filter_time', __('Filter time'));
        $show->field('record_recharge', __('Record recharge'));
        $show->field('record_send', __('Record send'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Filter());

        $form->number('filter_time', __('Filter time'));
        $form->number('record_recharge', __('Record recharge'));
        $form->number('record_send', __('Record send'));
        $form->number('record_balance', __('Record balance'));
        $form->number('record_order', __('Record order'));
        $form->number('record_goods', __('Record goods'));
        $form->number('record_storage', __('Record storage'));
        $form->number('record_take_away', __('Record take away'));
        $form->number('record_storage_man', __('Record storage man'));
        $form->number('record_take_away_man', __('Record take away man'));
        $form->number('record_pay', __('Record pay'));
        $form->number('purchase_to_material', __('Purchase to material'));
        $form->number('goods_sell', __('Goods sell'));
        $form->number('record_room', __('Record room'));

        return $form;
    }
}
